package com.heima.user.feign;

import com.heima.apis.user.IChannelClient;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.user.service.ApChannelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class ChannelSyncClient implements IChannelClient {
    
    @Resource
    private ApChannelService apChannelService;
    
    @PostMapping("/sync")
    @ApiOperation("同步自媒体频道到用户端")
    public ResponseResult syncChannel(@RequestParam("wmChannelId") Integer wmChannelId,
                                     @RequestParam("wmChannelName") String wmChannelName,
                                     @RequestParam("isDefault") Boolean isDefault,
                                     @RequestParam("status") Boolean status) {
        try {
            Integer apChannelId = apChannelService.syncWmChannel(wmChannelId, wmChannelName, isDefault, status);
            return ResponseResult.okResult(apChannelId);
        } catch (Exception e) {
            return ResponseResult.errorResult(com.heima.model.common.enums.AppHttpCodeEnum.SERVER_ERROR, "频道同步失败");
        }
    }
}
